//
//  XLCusomeCell.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/3.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLCusomeCell.h"
#import "XLPersonCenterTool.h"

@interface XLCusomeCell ()

//消费名称
@property (nonatomic, strong) UILabel *  consumeNameLbl;

//消费金豆
@property (nonatomic, strong) UILabel *  consumeBeansLbl;

//消费备注
@property (nonatomic, strong) UILabel *  consumeRemark;

//创建时间
@property (nonatomic, strong) UILabel *  creatTimeLbl;

@end

@implementation XLCusomeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //绘制界面显示
        [self setCustomeView];
        
    }
    
    return self;
}

#pragma mark    - - -Layout UI- - -

/**
 绘制界面显示
 */
- (void)setCustomeView
{
    
    //消费名称
    self.consumeNameLbl = [[UILabel alloc] init];
    
    self.consumeNameLbl.attributedText = [self setAttributeText:@"视频聊天" textColor:RGB(17, 17, 17) kernName:2 FontName:KFontNamePFMedium fontSize:17];
    [self setDecoratedForLabel:self.consumeNameLbl alignment:(NSTextAlignmentLeft)];
    [self.contentView addSubview:self.consumeNameLbl];
    
    [self.consumeNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(19);
        make.left.equalTo(self.contentView.mas_left).offset(kScale(15));
        make.width.lessThanOrEqualTo(@(ScreenWidth/2));
        make.height.mas_equalTo(24);
    }];
    
    //消费金豆
    self.consumeBeansLbl = [[UILabel alloc] init];
    
    self.consumeBeansLbl.attributedText = [self setAttributeText:@"-100金豆" textColor:RGB(66, 197, 112) kernName:0 FontName:KFontNamePFMedium fontSize:15];
    
    [self setDecoratedForLabel:self.consumeBeansLbl alignment:(NSTextAlignmentRight)];
    [self.contentView addSubview:self.consumeBeansLbl];
    
    [self.consumeBeansLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.consumeNameLbl.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-kScale(15));
        make.height.mas_equalTo(21);
    }];
    
    //消费备注
    self.consumeRemark = [[UILabel alloc] init];
    self.consumeRemark.attributedText = [self setAttributeText:@"开始：17：00 结束：17：00" textColor:RGB(102, 102, 102) kernName:1 FontName:KFontNamePFMedium fontSize:12];
    [self setDecoratedForLabel:self.consumeRemark alignment:(NSTextAlignmentLeft)];
    
    [self.contentView addSubview:self.consumeRemark];
    
    [self.consumeRemark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.consumeNameLbl.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-19);
        make.width.lessThanOrEqualTo(@(kScale(220)));
    }];
    
    //创建时间
    self.creatTimeLbl = [[UILabel alloc] init];
    
    self.creatTimeLbl.attributedText = [self setAttributeText:@"2018.04.16 15:03" textColor:RGB(153, 153, 153) kernName:1 FontName:KFontNamePFMedium fontSize:12];
    
    [self setDecoratedForLabel:self.creatTimeLbl alignment:(NSTextAlignmentLeft)];
    [self.contentView addSubview:self.creatTimeLbl];
    
    [self.creatTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.consumeRemark.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-kScale(15));
        make.height.mas_equalTo(17);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = RGB(238, 238, 238);
    [self addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScale(12));
        make.right.equalTo(self.mas_right).offset(-kScale(12));
        make.bottom.equalTo(self.mas_bottom).offset(-0.5);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark    - - - 设置数据 - - -

- (void)setModel:(XLConsumeModel *)model
{
    _model = model;
    
    if (_model) {
        
        //标题备注
        self.consumeNameLbl.attributedText = [self setAttributeText:model.Remarks textColor:RGB(17, 17, 17) kernName:2 FontName:KFontNamePFMedium fontSize:17];
        
        NSString *beans = @"";
        if(ValidStr(model.DisplayCard))
        {
            beans = [NSString stringWithFormat:@"-%@",model.DisplayCard];
        }else
        {
            //消耗金豆
            beans = [NSString stringWithFormat:@"-%@金豆",model.ChangeMoneyStr];
        }
        self.consumeBeansLbl.attributedText = [self setAttributeText:beans textColor:RGB(66, 197, 112) kernName:0 FontName:KFontNamePFMedium fontSize:15];
        
        //根据类型不同 显示消费情况
        //2-赠送礼物，4-解锁红包图片，5-解锁红包视频，，10-视频聊天扣费，12-直播送礼，25私信，30奇遇兑换
        
        NSString *remark;
        
        switch (model.ChangeType.integerValue) {

            case 2:{
                
                NSString *gift = [NSString stringWithFormat:@"%@ x %@",K_DEFULT(model.GiftName),model.CountNum];
                
                remark = gift;
                
                break;
            }
            case 4:{
                
                NSString *instruc = [NSString stringWithFormat:@"来自：%@",K_DEFULT(model.FromUser)];
                
                remark = instruc;
                
                break;
            }
            case 5:{
                
                NSString *instruc = [NSString stringWithFormat:@"来自：%@",K_DEFULT(model.FromUser)];
                
                remark = instruc;
                
                break;
            }
            case 10:{
                
                NSString *startTime = K_DEFULT(model.StartTime);
                
                NSString *endTime = K_DEFULT(model.EndTime);
                
                remark = [NSString stringWithFormat:@"开始：%@ 结束：%@",startTime,endTime];
                
                break;
            }
            case 12:{
                
                NSString *gift = [NSString stringWithFormat:@"%@ x %@",K_DEFULT(model.GiftName),model.CountNum];
                
                remark = gift;
                
                break;
            }
            case 25:{
                
                NSString *sendMsg = [NSString stringWithFormat:@"%@ x %ld条",K_DEFULT(model.Remarks),model.CountNumInt];
                
                remark = sendMsg;
                
                break;
            }
            case 30:{
                
                //奇遇兑换
                NSString *bean = [NSString stringWithFormat:@"成功兑换：%.lf秀币",model.ChangeMoney.doubleValue*1000];
                
                remark = bean;
                
                break;
            }
            case 40:{
                //视频卡
                NSString *startTime = K_DEFULT(model.StartTime);
                
                NSString *endTime = K_DEFULT(model.EndTime);
                
                remark = [NSString stringWithFormat:@"开始：%@ 结束：%@",startTime,endTime];
                
                break;
            }
            default:
                
                remark = @"";
                break;
        }
        
        self.creatTimeLbl.attributedText = [self setAttributeText:model.CreateTime textColor:RGB(153, 153, 153) kernName:1 FontName:KFontNamePFMedium fontSize:12];
        
        
        self.consumeRemark.attributedText = [self setAttributeText:remark textColor:RGB(102, 102, 102) kernName:1 FontName:KFontNamePFMedium fontSize:12];
        
    }
}


#pragma mark    - - -修饰控件方法- - -

//设置文字: 文字，颜色，字间距，字体字号
- (NSMutableAttributedString *)setAttributeText:(NSString *)text textColor:(UIColor *)color kernName:(CGFloat)kern FontName:(NSString *)fontName fontSize:(CGFloat)fontSize
{

    NSDictionary *dic = @{NSKernAttributeName:@(kern),
            NSFontAttributeName:[UIFont fontWithName:fontName size:fontSize],
            NSForegroundColorAttributeName:color
            };
    
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:dic];
    
    return attribute;
}

//设置label
- (void)setDecoratedForLabel:(UILabel *)label alignment:(NSTextAlignment)alignment
{
    label.textAlignment = alignment;
}




@end
